<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>持明法洲后台管理</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">layui 后台布局</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item"><a href="">控制台</a></li>
            <li class="layui-nav-item"><a href="">商品管理</a></li>
            <li class="layui-nav-item"><a href="">用户</a></li>
            <li class="layui-nav-item">
                <a href="javascript:;">其它系统</a>
                <dl class="layui-nav-child">
                    <dd><a href="">邮件管理</a></dd>
                    <dd><a href="">消息管理</a></dd>
                    <dd><a href="">授权管理</a></dd>
                </dl>
            </li>
        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:;">
                    <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
                    <shiro:principal/>
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="">基本资料</a></dd>
                    <dd><a href="">安全设置</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="">退了</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree"  lay-filter="nav_menu" id="nav_menu">

            </ul>
        </div>
    </div>
    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px;">
            <div class="layui-tab layui-tab-brief layui-tab-card" lay-allowClose="true" lay-filter="myTab">
                <ul class="layui-tab-title">
                    <li class="layui-this">欢迎页</li>
                </ul>
                <div class="layui-tab-content">
                    <div class="layui-tab-item layui-show">欢迎使用..xxxx</div>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-footer">
        <!-- 底部固定区域 -->
        © layui.com - 底部固定区域
    </div>
</div>
<script src="${pageContext.request.contextPath}/layui/layui.js"></script>
<script src="${pageContext.request.contextPath}/js/jquery-1.12.4.js"></script>
<script>
    function addTabs(menuName,url,menuId){
        layui.use('element', function(){
            var element = layui.element;
            // title 二级菜单的名字
            // content 引入新的页面 menuUrl
            // id 二级菜单的id
            // 以上三个参数 需要在调用函数的时候传进来
            if($("[lay-filter=myTab] li[lay-id="+menuId+"]").size() == 0){
                element.tabAdd("myTab",{
                    title:menuName,
                    content:'<iframe width="100%" height="100%" src="${pageContext.request.contextPath}'+url+'"></iframe>',
                    id:menuId
                })
            }else{
                element.tabChange("myTab",menuId);
            }
            element.tabChange("myTab",menuId);

        });
    }
    $(function () {
        $.ajax({
            "url":"${pageContext.request.contextPath}/menu/showAllMenu",
            "success":function (data) {
                var str = "";
                $.each(data,function (index1,menu1) {
                    str+="<li class=\"layui-nav-item \"><a class=\"\" href=\"javascript:;\">";
                    str+=menu1.menuName+"</a>";
                    $.each(menu1.child,function (index2,menu2) {
                        str+="<dl class=\"layui-nav-child\"><dd><a href=\"javascript:;\"" +"onclick='addTabs(\""+
                            menu2.menuName+"\",\""+menu2.url+"\","+menu2.menuId+")'"+
                            ">";
                        str+=menu2.menuName;
                        str+="</a></dd></dl>";
                    })
                    str+="</li>";
                });
                $("#nav_menu").html(str);
                layui.use('element', function(){
                    var element = layui.element;
                    element.render("nav","nav_menu");
                });
            }
        })
    })
    //JavaScript代码区域
    layui.use('element', function(){
        var element = layui.element;

    });
</script>
</body>
</html>